﻿using Microsoft.AspNetCore.Mvc;
using My.Admin.Dto.User;
using My.Admin.Model.System;
using My.Admin.Model;
using My.Core.DynamicWebApi.Attributes;
using My.Admin.Service.System.IService;
using Microsoft.AspNetCore.Identity;
using My.Admin.Service.System;
using System.ComponentModel;
using My.Admin.Dto.System;
using Mapster;
using Microsoft.AspNetCore.Authorization;

namespace My.Admin.Dynamic
{
    [Service("SysRoleController")]
	public class SysRoleController
	{
		private readonly ISysRoleService _sysRoleRep;
		private readonly ISysRoleMenuService _sysRoleMenuRep;
		private readonly UserManager _userManager;
		private readonly ISysUserRoleService _sysUserRoleService;
		public SysRoleController(ISysRoleService sysRoleRep, ISysRoleMenuService sysRoleMenuRep, UserManager userManager, ISysUserRoleService sysUserRoleService)
		{
			_sysRoleRep = sysRoleRep;
			_sysRoleMenuRep = sysRoleMenuRep;
			_userManager = userManager;
			_sysUserRoleService = sysUserRoleService;
		}

		/// <summary>
		/// 分页查询角色
		/// </summary>
		/// <returns></returns>
		[Authorize]
		[HttpPost]
		public async Task<PagedInfo<SysRole>> Page(PageRoleInput input)
		{
			return await _sysRoleRep.Page(input);
		}

		/// <summary>
		/// 获取角色列表
		/// </summary>
		/// <returns></returns>
		[Authorize]
		public async Task<List<RoleOutput>> GetList()
		{
			return await _sysRoleRep.GetList();
		}

		/// <summary>
		/// 根据角色Id获取菜单Id集合
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		public async Task<List<long>> GetOwnMenuList([FromQuery] RoleInput input)
		{
			return await _sysRoleMenuRep.GetRoleMenuIdList(new List<long> { input.Id });
		}

		/// <summary>
		/// 增加角色
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		[HttpPost]
		public async Task AddRole(AddRoleInput input)
		{
			await _sysRoleRep.AddRole(input);
		}

		/// <summary>
		/// 更新角色
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		[HttpPost]
		public async Task UpdateRole(UpdateRoleInput input)
		{
			await _sysRoleRep.UpdateRole(input);
		}

		/// <summary>
		/// 删除角色
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[Authorize]
		[HttpPost]
		public async Task DeleteRole(DeleteRoleInput input)
		{
			await _sysRoleRep.DeleteRole(input);
		}
	}
}
